<?php
/**
 * Created by PhpStorm.
 * User: THINK
 * Date: 2017/8/26
 * Time: 10:11
 */
namespace Home\Controller;

use Think\Controller;

class RegisterController extends Controller
{
    public function index(){
        $indexs = M('announce');
        $lists = $indexs->order('posttime desc')->limit(0,1)->select();
        $this->assign('lists',$lists);
        $this->display();
    }
    public function add(){
        $register =M('member');
        $s = I('post.');
        $dzyx = "/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/";
        if (preg_match($dzyx,$s['email'])){
            if ($s['password'] !="" && $s['nickname'] !=""){
                    if ($s['password'] == $s['rpassword']){
                        unset($s['rpasswoed']);
                        $s['regtime'] = date("Y-m-d H:i:s",time());
                        $s['loginip'] = get_client_ip();
                        $s['password']=md5($s['password']);
                        $list = $register->add($s);
                        if ($list>0){
                            echo '<script>alert("注册成功");</script>';
                            $this->redirect('login/index');
                        }else{
                            echo '<script>alert("注册失败，请重新输入");history.back();</script>';
                        }
                }else{
                    echo '<script>alert("两次密码不一致，请重新输入");history.back();</script>';
                }
            }else{
                echo '<script>alert("账号密码不对，请重新输入");history.back();</script>';
            }
        }else{
            echo '<script>alert("电子邮箱不对，请重新输入");history.back();</script>';
        }
    }
}